package com.common.jump;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.curry.android.util.IntentHelper;
import com.curry.android.util.StringUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.myhouse.activity.CertOkActivity;
import com.orangelife.mobile.myhouse.activity.HouseCert2Activity;
import com.orangelife.mobile.myhouse.activity.HouseCertActivity;
import com.orangelife.mobile.myhouse.activity.HouseCodeActivity;
import com.orangelife.mobile.myhouse.activity.HouseInviteActivity;
import com.orangelife.mobile.myhouse.activity.HouseListActivity;
import com.orangelife.mobile.myhouse.activity.HouseRentActivity;
import com.orangelife.mobile.myhouse.activity.HouseTipActivity;
import com.orangelife.mobile.myhouse.activity.HouseWaitConfirmActivity;
import com.orangelife.mobile.myhouse.activity.ResidentDetailActivity;
import com.orangelife.mobile.myhouse.activity.ResidentListActivity;
import com.orangelife.mobile.myhouse.entity.HouseBean;
import com.orangelife.mobile.myhouse.entity.IndustryBean;
import com.orangelife.mobile.myhouse.entity.IndustryEntity;

import java.util.ArrayList;

/**
 * 房屋的界面跳转
 * Created by wgf on 2016/6/22.
 *
 * @author wgf
 * @since v3.8.1
 */
public class HouseJumper {

    public static final String KEY_RESIDENT = "INTENT_KEY_RESIDENT";

    public static void jumpToInvite(Context context, String applicationID) {
        IntentHelper.getInstances().intentWithExtra(context, HouseInviteActivity.class, "applicationID", applicationID);
    }

    /** 重新跳回到认证界面 */
    public static void jumpToCert(Context context, String isRefill) {
        IntentHelper.getInstances().intentWithExtra(context, HouseCertActivity.class, "isRefill", isRefill);
    }

    public static void jumpToCertFromWeb(Activity activity) {
        IntentHelper.getInstances().intentWithExtra(activity, HouseCertActivity.class, "isFromWeb", "0");
    }

    /** 跳转到房屋列表 */
    public static void jumpToList(Context context) {
        IntentHelper.getInstances().getIntent(context, HouseListActivity.class);
    }

    public static void jumpToCertOk(Context context, IndustryEntity ib) {
        IntentHelper.getInstances().bundleWithExtra(context, CertOkActivity.class, ib);
    }

    public static void jumpToCertOk(Context context) {
        IntentHelper.getInstances().getIntent(context, CertOkActivity.class);
    }

    public static void jumpToCertOk(Context context, IndustryBean ib) {
        IntentHelper.getInstances().bundleWithExtra(context, CertOkActivity.class, ib);
    }

    /** 租客跳转到选择楼栋界面 */
//    public static void jumpToTenantCert2(Context context, String commID, String applicationID) {
//        Bundle bundle=new Bundle();
//        bundle.putString("applicationID", applicationID);
//        bundle.putString("commID", commID);
//        jumpToTenantCert2(context,bundle);
//    }

    public static void jumpToTenantCert2(Context context,Bundle bundle){
        Intent intent = new Intent(context, HouseCert2Activity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    /**
     * 非产权人认证的时候需要填写产权人提供的验证码
     *
     * @param ctx
     * @param applicationID 认证ID
     */
    public static void jumpToHouseCode(Context ctx, String applicationID) {
        IntentHelper.getInstances().intentWithExtraString(ctx, HouseCodeActivity.class, "applicationID", applicationID);
    }

    /** 如果不止一条，跳列表页。如果一条，判断是何种状态，待认证跳填码页，已过期跳提示页 */
    public static void switchJump(Context ctx, View v) {
        String applicationID = String.valueOf(v.getTag(R.string.code_0));
        String status = String.valueOf(v.getTag(R.string.code_1));
        if (!StringUtil.isContainBlank(applicationID, status)) {
            if (HouseBean.STATUS_WAIT.equals(status)) {
                HouseJumper.jumpToHouseCode(ctx, applicationID);
            } else if (HouseBean.STATUS_EXPIRE.equals(status)) {
                HouseJumper.jumpToCodeExpire(ctx, applicationID);
            }
        } else {
            jumpToHouseConfirmWait(ctx);
        }
    }

    public static void jumpToHouseConfirmWait(Context ctx) {
        IntentHelper.getInstances().getIntent(ctx, HouseWaitConfirmActivity.class);
    }

    /** 已有产业列表 */
//    public static void jumpToTenantHouseList(Context context, IndustryEntity ib, String commID) {
//        Bundle bundle = new Bundle();
//        bundle.putSerializable("industry", ib);
//        bundle.putString("commID", commID);
//        jumpToTenantHouseList(context, bundle);
//    }

    public static void jumpToTenantHouseList(Context context, Bundle bundle) {
        Intent intent = new Intent(context, HouseRentActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void jumpToOwnerCertFail(Context context, String info, String phone) {
        jumpToTip(context, HouseTipActivity.TYPE_TIP_INFO_ERROR, null, info, phone);
    }

    public static void jumpToCodeExpire(Context ctx, String applicationID) {
        jumpToTip(ctx, HouseTipActivity.TYPE_TIP_CODE_EXPAIR, applicationID, null, null);
    }

    public static void jumpToInfoError(Context ctx, String applicationID) {
        jumpToTip(ctx, HouseTipActivity.TYPE_TIP_CODE_EXPAIR, applicationID, null, null);
    }

    public static void jumpToTip(Context context, String tipType, String applicationID, String tip, String phone) {
//        IntentHelper.getInstances().intentWithExtra(context, HouseTipActivity.class, HouseTipActivity.INTENT_KEY_HOUSE_TIP, tipType);
        Intent intent = new Intent(context, HouseTipActivity.class);
        intent.putExtra(HouseTipActivity.INTENT_KEY_HOUSE_TIP, tipType);
        if (applicationID != null) {
            intent.putExtra("applicationID", applicationID);
        }
        if (tip != null) {
            intent.putExtra("house_tip_value", tip);
        }
       /*获取物业电话*/
        if (phone != null) {
            intent.putExtra("house_tip_phone", phone);
        }
        context.startActivity(intent);
    }


    /** 从房屋列表直接跳用户详情，非产权人不能查看用户列表，只能查看自己 */
    public static void jumpToResidentDetail(Context context, ArrayList<String> list) {
        jumpToResidentDetail(context, list, null, null, null);
    }

    /** 从用户列表跳转到用户详情，直接带数据过去 */
    public static void jumpToResidentDetail(Context context, String name, String phone, String identity) {
        jumpToResidentDetail(context, null, name, phone, identity);
    }

    /** 跳转到用户详情 */
    private static void jumpToResidentDetail(Context context, ArrayList<String> list, String name, String phone, String identity) {
        Intent intent = new Intent(context, ResidentDetailActivity.class);
        if (list == null) {
            intent.putExtra("resident_list_name", name);
            intent.putExtra("resident_list_phone", phone);
            intent.putExtra("resident_list_identity", identity);
        } else {
            intent.putStringArrayListExtra(KEY_RESIDENT, list);
        }
        context.startActivity(intent);
    }

    /** 跳转到用户列表 */
    public static void jumpToResidentList(Context context, ArrayList<String> list) {
        Intent intent = new Intent(context, ResidentListActivity.class);
        intent.putStringArrayListExtra(KEY_RESIDENT, list);
        context.startActivity(intent);
    }

}
